<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
	<div>
		<select name="" id="province">
			<option value="">请选择</option>
		</select>
		<select name="" id="city">
			<option value="">请选择</option>
		</select>
		<select name="" id="county">
			<option value="">请选择</option>
		</select>
	</div>

</body>
<script src="city.js"></script>
<script type="text/javascript">
function $(s){
	return document.querySelectorAll(s);
}
var province = $("#province")[0],
city=$("#city")[0],
county =$("#county")[0]
/*
cityData.reduce(function(a,b){
	
},"<option value="">请选择</option>")
 */
function createData(ele,arr){
for (var i = 0; i < cityData.length; i++) {
	province.innerHTML += "<option value=\""+cityData[i].name+"\">"+cityData[i].name+"</option>";
}
}
createData()
province.onchange = function(){
	var val = this.value;
	for (var i = 0; i < cityData.length; i++) {
		if(val == cityData[i].name&&cityData[i].city&&cityData[i].city.length>0){
			//获取的数组市，就是cityDate[i].city
			createData(city,cityData[i].city);
			for (var j = 0; j < cityData.city.length; j++) {
				city.innerHTML+="<option value"
			}
		}
	}
}

city.onchange=function(){
	for (var i = 0; i < cityData.length; i++) {//找市的数组
		var p = cityData[i].name;
		var c = cityData[i].city;
		for (var j = 0; j < c.length; j++) {//找县的数组
			//c的name是市的名字
			if(c[j].name==this.value){//当前选择的市和哪个市名相等
			//c[j].districtAndCounty 县的数组
			county.innerHTML="<option value=''>请选择</option>"
			for (var k = 0; k <c[j].districtAndCounty.length; i++) {
				[i]
			}
				createData(county,c[j].districtAndCounty);
			}
		}
	}
}
</script>
</html>